//
//  HomeViewController.m
//  NoNameAmazing
//
//  Created by 刘金壮 on 17/6/24.
//  Copyright © 2017年 北京执行力科技有限公司. All rights reserved.
//

#import "HomeViewController.h"
#import "SchoolNewsController.h"
#import "SchoolNoticeController.h"
#import "SchoolNoticeController.h"
#import "HomeHeaderView.h"
#import "HeroSegmentView.h"
#import "SDCycleScrollView.h"
@interface HomeViewController ()
@property (nonatomic ,strong) HomeHeaderView *headView;
@property (nonatomic ,strong) HeroSegmentView * heroView;
@property(nonatomic,strong)SDCycleScrollView *sycleScrollView;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.headView.frame = CGRectMake(0, 0, kScreen_Width, 269);
    self.headView.backgroundColor = [UIColor redColor];
//    [self.view addSubview:self.headView];
    [self prepareUI];
    SchoolNewsController *introduction = [[SchoolNewsController alloc]initWithNibName:@"SchoolNewsController" bundle:nil];
    introduction.title = @"校园新闻";
    SchoolNoticeController *product = [[SchoolNoticeController alloc]initWithNibName:@"SchoolNoticeController" bundle:nil];
    product.title = @"校园公告";
    SchoolNoticeController *address = [[SchoolNoticeController alloc]initWithNibName:@"SchoolNoticeController" bundle:nil];
    address.title = @"校园通知";
    _heroView = [[HeroSegmentView alloc] initWithFrame:CGRectMake(0, (kScreen_Width/3)+125+44, kScreen_Width, kScreen_Height -54 -64-280)];
    [self.view addSubview:_heroView];
    [_heroView setViewControllers:@[introduction, product, address] owner:self];
    UIView *segView = [_heroView topControlViewWithFrame:CGRectMake(0, (kScreen_Width/3)+125, kScreen_Width, 44) defaultColor:UIColorFromRGB(0x333333) selectedColor:UIColorFromRGB(0x1A7BE5)];
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = UIColorFromRGB(0xe6e6e6);
    [lineView setFrame:CGRectMake(0, 43, kScreen_Width, 1)];
    [segView addSubview:lineView];
    
    [self.view addSubview:segView];
    [self loadCarouselshowData];
    [self loadNews];
    
}
- (void)prepareUI{//准备UI
    _sycleScrollView = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 125)];
    _sycleScrollView.currentPageDotImage = [UIImage imageNamed:@"point_black-1"];
    _sycleScrollView.pageDotImage = [UIImage imageNamed:@"point_black_pre-1"];
    _sycleScrollView.autoScroll = YES;
    _sycleScrollView.currentPageDotColor = [UIColor whiteColor];
    [self.view addSubview:_sycleScrollView];
    
    
    for (int i = 0; i<3; i++) {
        UIButton *button = [[UIButton alloc]init];
        [button setFrame:CGRectMake(i*kScreen_Width/3, 125, kScreen_Width/3, kScreen_Width/3)];
        [self.view addSubview:button];
        UIView *lineView = [[UIView alloc]init];
        [lineView setFrame:CGRectMake((i+1)*(kScreen_Width/3), 125+30, 1, (kScreen_Width/3)-60)];
        lineView.backgroundColor = UIColorFromRGB(0xc0c0c0);
        [self.view addSubview:lineView];
        
        NSArray *imageArr = @[@"学院概况",@"地图",@"通讯录"];
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:imageArr[i]];
        [button addSubview:imageView];
        
        NSArray *titleArr = @[@"学院概况",@"校园地图",@"通讯录"];
        UILabel *label = [[UILabel alloc]init];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = [UIColor grayColor];
        label.text = titleArr[i];
        [button addSubview:label];
        if (i == 0) {
            [imageView setFrame:CGRectMake((kScreen_Width/3)/2-30, (kScreen_Width/3)/2-32, 40, 40)];
            [label setFrame:CGRectMake(CGRectGetMinX(imageView.frame)-5, CGRectGetMaxY(imageView.frame)+5, 50, 20)];
        }else if (i == 1){
            [imageView setFrame:CGRectMake((kScreen_Width/3)/2-20, (kScreen_Width/3)/2-32, 40, 40)];
            [label setFrame:CGRectMake(CGRectGetMinX(imageView.frame)-5, CGRectGetMaxY(imageView.frame)+5, 50, 20)];
        }else{
            [imageView setFrame:CGRectMake((kScreen_Width/3)/2-10, (kScreen_Width/3)/2-32, 40, 40)];
            [label setFrame:CGRectMake(CGRectGetMinX(imageView.frame)-5, CGRectGetMaxY(imageView.frame)+5, 50, 20)];
        }
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = UIColorFromRGB(0xf9f9f9);
        view.frame = CGRectMake(0, CGRectGetMinY(button.frame)-10, CGRectGetWidth(button.frame), 10);
        [button addSubview:view];
        
       
       
       
    }
    
}
- (void)loadNews{//获取新闻
    NSDictionary *params = @{@"name":@"news"};
    [NetWorkManager requestWithType:1 withUrlString:@"/plugin/getPluginByName.do" withParaments:params withSuccessBlock:^(id object) {
        if ([object[@"status"] integerValue] == 1) {
            NSString *url = object[@"pluginName"];
            NSString *urlStr = [NSString stringWithFormat:@"/%@/webService/InformationService/information/getAppInformation/%@",url,[us objectForKey:kRoleid]];
            [NetWorkManager requestWithType:0 withUrlString:urlStr withParaments:nil withSuccessBlock:^(id object) {
                if ([object[@"status"] integerValue]==1){
                    
                }
            } withFailureBlock:^(NSError *error) {
                
            } progress:^(float progress) {
                
            }];
            
        }
    } withFailureBlock:^(NSError *error) {
        
    } progress:^(float progress) {
        
    }];
}

- (void)loadCarouselshowData{//获取轮播图
    NSDictionary *params = @{@"name":@"carouselshow"};
    [NetWorkManager requestWithType:1 withUrlString:@"/plugin/getPluginByName.do" withParaments:params withSuccessBlock:^(id object) {
        NSString *imageName;
        if ([object[@"status"] integerValue] == 1) {
            NSString *url = object[@"pluginName"];
            imageName = url;
            NSString *urlStr = [NSString stringWithFormat:@"/%@/webService/carouselService/carousel/getCarousel/homeBanner/%@",url,[us objectForKey:kRoleid]];
            [NetWorkManager requestWithType:0 withUrlString:urlStr withParaments:@"" withSuccessBlock:^(id object) {
                 NSMutableArray *titleArr = [NSMutableArray array];
                if ([object[@"status"]integerValue] == 1) {
                    NSString *BaseURL = [us objectForKey:baseUrl];
                    for (NSString *str  in object[@"carousel"]) {
                        NSString *str1 = [NSString stringWithFormat:@"%@/%@/%@",BaseURL,imageName,str];
                        ;
                        [titleArr addObject:str1];
                    }
                    _sycleScrollView.imageURLStringsGroup = titleArr;
                }
            } withFailureBlock:^(NSError *error) {
                
            } progress:^(float progress) {
                
            }];
        }
    } withFailureBlock:^(NSError *error) {
        
    } progress:^(float progress) {
        
    }];
}


#pragma mark - 懒加载 -
- (HomeHeaderView *)headView{
    if (!_headView) {
        _headView = [[NSBundle mainBundle] loadNibNamed:@"HomeHeaderView" owner:self options:nil].lastObject;
        
    }
    return _headView;
}





@end
